package com.wuliu.controller;

import cn.hutool.core.bean.BeanUtil;
import com.wuliu.common.core.domain.ApiResult;
import com.wuliu.common.core.domain.entity.BasCust;
import com.wuliu.common.utils.DateUtils;
import com.wuliu.common.utils.SecurityUtils;
import com.wuliu.common.utils.ThreadLocalContext;
import com.wuliu.system.domain.dto.applet.BasCustDto;
import com.wuliu.system.service.IBasCustService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @author realue
 * @version 1.0
 * @date 2023-11-01 22:17
 */
@RestController
@RequestMapping("/applet/cust")
@Api(tags = {"用户控制器"})
public class BasCustController {
    @Resource
    private IBasCustService basCustService;

    @ApiOperation(value = "当前用户信息")
    @PostMapping("/getInfo")
    public ApiResult<BasCust> getInfo() {
        return ApiResult.success(SecurityUtils.getBasCust());
    }

    @ApiOperation(value = "修改用户信息")
    @PostMapping("/edit")
    public ApiResult<Integer> edit(@RequestBody @Validated BasCustDto dto) {
        BasCust basCust = new BasCust();
        BeanUtil.copyProperties(dto, basCust);
        return ApiResult.success(basCustService.updateBasCust(basCust));
    }

}
